#!/bin/bash

# ------------------------初始化 common-info
# 读取当前脚本所在位置
BASH_PATH=$(cd "$(dirname "$0")";pwd)
common_info_path=/opt/daas-info/common-info.conf
# 加载common_info配置文件
source $common_info_path

# ------------------------ 配置信息
# 定义工程名，也是安装路径的一部分,不带版本号和特殊符号
projectName=$(basename $(cd ${BASH_PATH}/../../;pwd))
# 定义配置模板文件夹路径
backupPath=${BASH_PATH}/../../uninstall_backup$(date -d now +"%Y%m%d_%H-%M-%S")

# 需要备份的目录和文件
# 从common-info中获取nginx配置文件路径
daasNginxConfPath=${nginx_conf_path}/oss_access_nginx.conf
# 已经安装的前端路径
installPath=${frontend_install_path}/${projectName}

# ------------------------ 进行备份
mkdir -p ${backupPath}
echo "[INFO] Check and create the backup directory!"


echo "[INFO] On the backup ..."
# 执行备份任务
mv ${daasNginxConfPath} ${backupPath}
mv ${installPath} ${backupPath}
systemctl reload nginx
if [ $? == 0 ]; then
    echo -e "[INFO]  $projectName Uninstall complete.\n"
else
    echo -e "[ERROR] The installation path does not exist when backing up.\n"
fi
